//
//  ViewController.m
//  壳牌喜力促销积分商城
//
//  Created by xrd on 15/3/13.
//  Copyright (c) 2015年 xrd. All rights reserved.
//

#import "ViewController.h"
#import "AFNetworking.h"
#import "MBProgressHUD+MJ.h"
#import "NSArray+Log.h"
#import "WCAlertView.h"
#import "ProtolViewController.h"
#define userIsAgreenProtol @"userIsAgreenProtol"
@interface ViewController ()<NSURLConnectionDelegate,UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *username;

@property (weak, nonatomic) IBOutlet UITextField *password;
// 登录按钮
@property (weak, nonatomic) IBOutlet UIButton *login;

@end

@implementation ViewController
- (IBAction)textField:(UITextField *)sender {
    // 当用户名和密码都有时 ，login才可以点击
    self.login.enabled = (self.username.text.length && self.password.text.length);
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
//    NSLog(@" 沙河路径 %@",[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]);

//    self.username.text = @"123";
//    self.password.text = @"123";
    
    
    _password .delegate  = self;
    _username .delegate  = self;
    _password.secureTextEntry = YES;
    
    
    
}


#pragma -  mark 登陆
- (IBAction)loginBtn:(id)sender {
    

    

//if ([self.username.text isEqualToString: @"123" ]&&[self.password.text isEqualToString: @"123"])
    /**
     *  下面所有的代码，只有在登录成功的时候，在需要写！登录不成功，不能让它执行下面的代码
     */
//========下面这句只有在测试的时候，在用，不然要注释掉， 它只是清除偏好的数据，让其重新开始==============//
 [[NSUserDefaults standardUserDefaults] removeObjectForKey:userIsAgreenProtol];
//==================================================================================//
  
    UIWindow *window = [UIApplication sharedApplication ].keyWindow;
    NSUserDefaults *userDefaults= [NSUserDefaults standardUserDefaults];
    NSNumber *agreenNumber = [userDefaults objectForKey:userIsAgreenProtol];
    if(agreenNumber == nil){
        ProtolViewController *pVc = [[ProtolViewController alloc] init];
        window.rootViewController = pVc;
    }else {
        UIStoryboard *sb = [UIStoryboard storyboardWithName:@"TwoMain" bundle:nil];
        window.rootViewController = sb.instantiateInitialViewController;
    }
    
    
    



//开始网络请求

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];

NSDictionary *parameters = @{@"username":@"zhangn",@"password":@"zhangsan"};

[manager POST:@"http://192.168.1.200:8080/ShellService/forStage/ForeStageAction_checkLogin.action"parameters:parameters
 
     success:^(AFHTTPRequestOperation *operation,id responseObject) {
         
         NSLog(@"Success: %@", responseObject);
         
     }failure:^(AFHTTPRequestOperation *operation,NSError *error) {
         
         NSLog(@"Error: %@", error);
         
     }];
}


@end
